package com.itstyle.seckill.topic.jichu;

import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executors;

/**
 * @Auther: liuwenxiang
 * @Date: 2020/4/15 00:45
 * @Description:
 */
public class CopyOnWriteTest {

    static CopyOnWriteArrayList<String> copyOnWriteArrayList = new CopyOnWriteArrayList();

    public static void main(String[] args) {
        int i=0;
        while(true){
            i++;
            if(i==6){
                break;
            }
            if(i%2==0){
                Executors.newCachedThreadPool().execute(new Runnable() {
                    @Override
                    public void run() {
                        copyOnWriteArrayList.add("haha");
                    }
                });
            }else{
                Executors.newCachedThreadPool().execute(new Runnable() {
                    @Override
                    public void run() {

                    }
                });
            }

        }

    }
}
